/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __PROJECT_MANAGER_H__
#define __PROJECT_MANAGER_H__

#include "GameProject.h"

namespace PQEngine
{
	//every file in Gdk3d project is base on this file
	//manage projects data
	class ProjectManager
	{
	public:
		static const std::string PERSIS_FILE_NAME;
	protected:
		ProjectManager();
	public:
		static ProjectManager& getSingleton();
		inline std::string getProjectPath()
		{
			return _projectPath;
		}

		inline int getProjectCount()
		{
			return _projectPathes.size();
		}

		inline std::string getProjectPath(int index)
		{
			assert(index>=0&&index<_projectPathes.size());
			return _projectPathes[index];
		}

		inline std::string getProjectName(int index)
		{
			assert(index>=0&&index<_projectPathes.size());
			std::string path=_projectPathes[index];
			int pos=path.find_last_of("/");
			std::string name=path.substr(pos+1);
			return name;
		}


		inline std::vector<std::string> getProjectPathes()
		{
			return _projectPathes;
		}

		inline int getAssetArchiveCount()
		{
			return _project->getAssetArchiveCount();
		}

		inline std::string getAssetArchiveName(int index)
		{
			return _project->getAssetArchiveName(index);
		}
		
		/*Return file count in specified asset archive
		*/
		inline int getAssetArchiveFileCount(int index)
		{

			return _project->getAssetArchiveFileCount(index);
		}
		
		/*Return file name in specified asset archive with specified index
		*/
		inline std::string getAssetArchiveFileName(int archiveIndex,int fileIndex)
		{
			return _project->getAssetArchiveFileName(archiveIndex,fileIndex);
		}

		
		void saveProject();
		
		/*Create project in specified path with specified name
		@param path path that the project in.
		@param name the name of the project.
		*/
		bool createProject(std::string path,std::string name);
		void loadProject(int index);

		/*Create asset archive for current project
		*/
		GPKArchive* createAssetArchive(std::string name);

		/*Add local file to index-th .gpk asset archive
		*/
		inline bool addAssetArchiveFile(int index,std::string fileName)
		{
			return _project->addAssetArchiveFile(index,fileName);
		}


		void persist();
	private:
		std::vector<std::string> _projectPathes;//store projects full path
		std::string _projectPath;
		int _projectIndex;//current selected project index

		GameProject* _project;//current loaded project
		
	};
}
#define GNgProjectManager PQEngine::ProjectManager::getSingleton()

#endif
